﻿var currentNode = null;
function showMenu(node, e) {
    currentNode = node;
    var menu = TreeContextMenu;
    if (node.browserEvent) {
        this.menuNode = this.getRootNode();
        menu.nodeName = "";
        this.getSelectionModel().clearSelections();
        e = node;
    }
    else {
        this.menuNode = node;
        menu.nodeName = node.text;

        node.select();
    }
    if (!Ext.isEmpty(node.attributes.urlcard)) {
        menu.showAt([e.getXY()[0], e.getXY()[1] + 0]);
        e.stopEvent();
    }
}
function NewFromMenu(item, e) {
    TreeNodeDbClick(currentNode, e, currentNode.attributes.urlcard)
}
function OpenFromMenu(item, e) {
    TreeNodeDbClick(currentNode, e, currentNode.attributes.url)
}
function dfWorkingDate_KeyUP(el, e) {
    var inputVar = el.getRawValue();
    if (e.ENTER == e.getKey()) {
        el.validate();
        el.setValue(el.getRawValue());
        if (el.getValue() != '') {
            txtDate.hideMenu();
            Cookies.set('wd', dfWorkingDate.getRawValue()); NAV2WEB.SetWorkingDate(el.getRawValue());
        }
        else {
            el.markInvalid();
            el.setRawValue(inputVar);
        }

    }

}
function doSave(key, e) {
    if (e.ctrlKey) {
        var iframmain = document.getElementById(panelMain.iframe.id);
        if (typeof (iframmain.contentWindow.doSave) != 'undefined') {
            iframmain.contentWindow.doSave();
        }
    }

}
function doDelete(key, e) {
    if (e.ctrlKey) {
        var iframmain = document.getElementById(panelMain.iframe.id);
        if (typeof (iframmain.contentWindow.tbarDelete) != 'undefined') {
            iframmain.contentWindow.tbarDelete.fireEvent('Click');
        }
    }
}
function LoadTree(item, e, treeID) {
    for (i = 0; i < PanelList.items.length; i++) {
        //if (PanelList.items[i].xtype == "") {
        //PanelList.items[i].id.match('^tree')
        PanelList.items.items[i].doHide();
        //}
    }
    PanelList.items.get(treeID).focus();
    PanelList.items.get(treeID).show();
}
function TreeNodeDbClick(node, e, url) {
    if (e.ctrlKey) {
        window.open(url, '_blank', 'toolbar=0,status=0,resizable=1,scrollbars=1,location=0');
        return;
    }
    load(url, node.text, node.id);
}
//Region add tabpanel  (dungnc modified)
function load(url, title, idnodeMenu) {

    //var iframmain = document.getElementById(panelMain);
    // var dsadsada = iframmain.contentWindow.document.title.toString().replace('_', '');
    var IdTab = idnodeMenu;
    addTab(panelMain, IdTab, url, title);
}
function removeTab() {
    var tab = panelMain.getActiveTab();
    panelMain.closeTab(tab, "hide");
}
function reloadFrameMain(id) {

    var windowParent = window.parent.Ext.getCmp(id);
    windowParent.reload(true);
}
function setWebSelection(entry_no,flag) {

    if (flag) {
      //  NAV2WEB.setWebSelection(entry_no);
    } else {
  //  NAV2WEB.setWebSelectionForCus(entry_no)
    }
}
var addTab = function(tabPanel, id, url, title) {
    var tab = tabPanel.getComponent(id);

    if (!tab) {
        tab = tabPanel.add({
            id: id,
            title: title,
            tabTip: title,
            closable: true,
            autoLoad: {
                showMask: true,
                url: url,
                mode: "iframe"
            }
        });
    }
    else if (url != tab.autoLoad.url) {
        tab.load(url);
    }
    tabPanel.setActiveTab(tab);
}
//EndRegion add tabpanel

function setTitle(title) {
    var iframmain = document.getElementById(panelMain.iframe.id);
    //iframmain.contentWindow.Ext.ComponentMgr.register(KeyMap1);
    //KeyMap1.item = iframmain.contentWindow.Ext.isGecko ? iframmain.contentWindow.Ext.getDoc() : iframmain.contentWindow.Ext.getBody();
    if (title) {
        document.title = title.toString().replace('_', '');
    }
    else {
        document.title = iframmain.contentWindow.document.title.toString().replace('_', '');
    }
}
function LoadMenuLevel(parentid) {
    PanelList.clearContent();
}

function exit() {
    panelMain.clearContent();
    document.title = "ASOI2WA";
}

function reload() {
var windowParent = window.parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    var iframmain = document.getElementById(panelMain.iframe.id);
    var hdfmode = iframmain.contentWindow.Ext.getCmp('hdfMode');
    var No = iframmain.contentWindow.Ext.getCmp('No');
    var mode = 'view';
    if (typeof (hdfmode) != 'undefined') {
        mode = hdfmode.getValue();
    }
    if (mode == 'new') {
        mode = 'edit';
    }

    if (panelMain.autoLoad.url) {
        var url = iframmain.contentWindow.location.href;
        url = url.replace('mode=new', 'mode=' + mode);
        url = url.replace('mode=view', 'mode=' + mode);
        if (No) {
            //url = url.toLowerCase().replace('no=', 'old=');
            //url = url + '&no=' + No.getValue();
        }
        panelMain.load(url);
    }

}


function loadLogin(url) {
    ucLogin_Window1.show();
}
